import '../public.dart';
import 'base_model.dart';

/// 基础实体
class UserAccountModel extends BaseModel {
  int userId;
  int scoreToday;
  String scoreTodayUnit;
  int scoreTodayExpire;
  int score;
  String scoreUnit;
  String scoreExchange;
  int totalScore;
  String totalScoreUnit;
  int limit;
  String alipayUser;
  String alipayName;
  bool isNew;
  int remainDay;
  int todayRead;
  int serversTime;
  int rate;

  UserAccountModel.fromJson(Map<String, dynamic> data) : super.fromJson(data) {
    int _score = data['score'] ?? 0;
    int _rate = data['rate'] ?? 10000;
    userId = data['user_id'] ?? 0;
    scoreToday = data['score_today'] ?? 0;
    scoreTodayUnit = StringUtil.numberToUnitStr(data['score_today'] ?? 0);
    scoreTodayExpire = data['score_today_expire'] ?? 0;
    score = data['score'] ?? 0;
    scoreUnit = StringUtil.numberToUnitStr(data['score'] ?? 0);
    scoreExchange = StringUtil.exchangeRMB(_score, _rate);
    totalScore = data['total_score'] ?? 0;
    totalScoreUnit = StringUtil.numberToUnitStr(data['total_score'] ?? 0);
    limit = data['limit'] ?? 0;
    alipayUser = data['alipay_user'] ?? '';
    alipayName = data['alipay_name'] ?? '';
    isNew = (data['is_new'] ?? 0) == 0 ? true : false;
    remainDay = data['remain_day'] ?? 0;
    todayRead = data['today_read'] ?? 0;
    serversTime = data['servers_time'] ?? 0;
    rate = _rate;
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      'userId': userId,
      'scoreToday': scoreToday,
      'scoreTodayUnit': scoreTodayUnit,
      'scoreTodayExpire': scoreTodayExpire,
      'score': score,
      'scoreUnit': scoreUnit,
      'scoreExchange': scoreExchange,
      'totalScore': totalScore,
      'totalScoreUnit': totalScoreUnit,
      'limit': limit,
      'alipayUser': alipayUser,
      'alipayName': alipayName,
      'isNew': isNew,
      'remainDay': remainDay,
      'todayRead': todayRead,
      'serversTime': serversTime,
      'rate': rate
    };
  }
}
